<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var ossFileDataGrid;
    $(function() {
        ossFileDataGrid = $('#ossFileDataGrid').datagrid({
        url : '${path}/admin/ossFile/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        idField : 'id',
        sortName : 'id',
        sortOrder : 'desc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [
            {
                width : '50',
                title : '多选',
                field:'ck',
                checkbox:true 
            }
			,{
           	 	width : '100',
           	 	title : 'id',
           	 	field : 'id',
           	 	sortable : true,

			}
			,{
           	 	width : '90',
           	 	title : 'bucketName',
           	 	field : 'bucket',
           	 	sortable : true,

			}
			,{
           	 	width : '190',
           	 	title : 'OssKey',
           	 	field : 'ossKey',
           	 	sortable : true,

			}
			,{
           	 	width : '150',
           	 	title : 'fileName',
           	 	field : 'name',
           	 	sortable : true,

			}
			,{
           	 	width : '310',
           	 	title : 'fileUrl',
           	 	field : 'url',
           	 	sortable : true,
                formatter : function(value, row, index) {
                    return "<a href='" + value + "' target='_blank'>"+value+"</a>";
                }

			}
			,{
           	 	width : '100',
           	 	title : '类型',
           	 	field : 'type',
           	 	sortable : true,

			}
			,{
           	 	width : '150',
           	 	title : '创建时间',
           	 	field : 'createdTime',
           	 	sortable : true,

			}
			,{
                width : '100',
                title : '状态',
                field : 'status',
                sortable : true,
                ${ dic:getBusDictListToCase('DATA_STATUS')}

            }
			,{
            field : 'action',
            title : '操作',
            width : 260,
            formatter : function(value, row, index) {
                var str = '';
                <shiro:hasPermission name="/admin/ossFile/edit">
                    str += $.formatString('<a href="javascript:void(0)" class="ossFile-easyui-linkbutton-look" data-options="plain:true,iconCls:\'fi-eye icon-green\'" onclick="ossFileEditFun(\'{0}\');" >编辑</a>', row.id);
                </shiro:hasPermission>
                <shiro:hasPermission name="/admin/ossFile/delete">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="ossFile-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="ossFileDeleteFun(\'{0}\');" >删除</a>', row.id);
                </shiro:hasPermission>
                str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                str += $.formatString('<a href="javascript:void(0)" class="ossFile-easyui-linkbutton-del2oss" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="ossFileDelete2OssFun(\'{0}\');" >从OSS中删除</a>', row.id);
                return str;
            }
        	}
          ] ],
        singleSelect: false,
        selectOnCheck: true,
        checkOnSelect: true,
        onLoadSuccess:function(data){
            if(data){
                $.each(data.rows, function(index, item){
                    if(item.checked){
                        $('#contentDataGrid').datagrid('checkRow', index);
                    }
                });
            }
            $('.ossFile-easyui-linkbutton-look').linkbutton({text:'查看'});
            $('.ossFile-easyui-linkbutton-del').linkbutton({text:'删除'});
            $('.ossFile-easyui-linkbutton-del2oss').linkbutton({text:'从OSS中删除'});

        },
        toolbar : '#ossFileToolbar'
    });
});

/**
 * 添加框
 * @param url
 */
function ossFileAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : "60%",
        height : "80%",
        href : '${path}/admin/ossFile/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = ossFileDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#ossFileAddForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 查看
 */
function ossFileEditFun(id) {
    parent.$.modalDialog({
        title : '查看',
        width : "700",
        height : "300",
        href :  '${path}/admin/ossFile/editPage?id=' + id
    });
}


/**
 * 删除
 */
 function ossFileDeleteFun(id) {
     if (id == undefined) {//点击右键菜单才会触发这个
         var rows = ossFileDataGrid.datagrid('getSelections');
         id = rows[0].id;
     } else {//点击操作里面的删除图标会触发这个
         ossFileDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
     }
     parent.$.messager.confirm('询问', '您是否要删除当前数据？', function(b) {
         if (b) {
             progressLoad();
             $.post('${path}/admin/ossFile/delete', {
                 id : id
             }, function(result) {
                 if (result.success) {
                     parent.$.messager.alert('提示', result.msg, 'info');
                     ossFileDataGrid.datagrid('reload');
                 }
                 progressClose();
             }, 'JSON');
         }
     });
}
/**
 * 删除
 */
function ossFileDelete2OssFun(id) {
    parent.$.messager.confirm('询问', '您是否要从OSS中删除当前数据？', function(b) {
        if (b) {
            progressLoad();
            $.post('${path}/admin/ossFile/delete2Oss', {
                id : id
            }, function(result) {
                if (result.success) {
                    parent.$.messager.alert('提示', result.msg, 'info');
                    ossFileDataGrid.datagrid('reload');
                }
                progressClose();
            }, 'JSON');
        }
    });
}
/**
 * 批量删除
 */
function ossFileDeleteIdsFun(){
	var ids = getossFileSelectionsIds();
 	if(ids.length == 0){
 		$.messager.alert('提示','未选中数据!');
 		return ;
 	}
 	$.messager.confirm('确认','确定删除ID为 '+ids+' 的记录,共'+ids.split(",").length+'记录吗？',function(r){
 	    if (r){
 	    	var params = {"ids":ids};
         	$.post("${path}/admin/ossFile/deleteIds",params, function(result){
         		result=JSON.parse(result);
     			if(result.success){
     				parent.$.messager.alert('提示', result.msg, 'info');
                    ossFileDataGrid.datagrid('reload');
     			}else{
     				$.messager.alert('错误提示',data.msg);
     			}
     		});
 	    }
 	});
}
/**
 * 获得选中的记录
 */
function getossFileSelectionsIds(){
	var itemList = $("#ossFileDataGrid");
	var sels = itemList.datagrid("getSelections");
	var ids = [];
	for(var i in sels){
		ids.push(sels[i].id);
	}
	ids = ids.join(",");
	sels.length=0;
	return ids;
}

/**
 * 清除
 */
function ossFileCleanFun() {
    $('#ossFileSearchForm input').val('');
    ossFileDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function ossFileSearchFun() {
     ossFileDataGrid.datagrid('load', $.serializeObject($('#ossFileSearchForm')));
}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" class="lay_box" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="ossFileSearchForm">
            <div class="tab_box">
                <div class="tab_a">
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="ossFileSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="ossFileCleanFun();">清空</a>
                </div>
                <ul class="list">
					<li>
                        <label>fileUrl:</label>
                        <input name="url" type="text"  class="easyui-textbox" data-options="height:29,width:200"/>
                    </li>
					<li>
                        <label>类型:</label>
                        <input name="type" type="text"  class="easyui-textbox" data-options="height:29"/>
                    </li>

                </ul>
            </div>
        </form>
     </div>
 
    <div data-options="region:'center',border:false">
        <table id="ossFileDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="ossFileToolbar" style="display: none;">
    <%--<shiro:hasPermission name="/admin/ossFile/add">--%>
        <%--<a onclick="ossFileAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>--%>
    <%--</shiro:hasPermission>--%>
        <shiro:hasPermission name="/admin/ossFile/deleteIds">
        <a onclick="ossFileDeleteIdsFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-x icon-red'">删除</a>
    </shiro:hasPermission>
</div>